#ifndef __GIC_H_
#define __GIC_H_
#include <stdint.h>

#define GICD_BASE 0x00A01000  // Distributor
#define GICC_BASE 0x00A02000  // CPU Interface
#define GICD_CTLR         (*(volatile uint32_t *)(GICD_BASE + 0x000))
#define GICD_TYPER        (*(volatile uint32_t *)(GICD_BASE + 0x004))
#define GICD_ISENABLER(n) (*(volatile uint32_t *)(GICD_BASE + 0x100 + 4*(n)))
#define GICD_ICENABLER(n) (*(volatile uint32_t *)(GICD_BASE + 0x180 + 4*(n)))
#define GICD_ICPENDR(n)   (*(volatile uint32_t *)(GICD_BASE + 0x280 + 4*(n))) 
#define GICD_IPRIORITY(n) (*(volatile uint32_t *)(GICD_BASE + 0x400 + 4*(n)))

#define GICC_CTLR         (*(volatile uint32_t *)(GICC_BASE + 0x000))
#define GICC_PMR          (*(volatile uint32_t *)(GICC_BASE + 0x004))
#define GICC_IAR          (*(volatile uint32_t *)(GICC_BASE + 0x00C))
#define GICC_EOIR         (*(volatile uint32_t *)(GICC_BASE + 0x010))

void gic_init(void);
void gic_enable_irq(uint32_t irq);
void gic_disable_irq(uint32_t irq);
void gic_set_priority(uint32_t irq, uint8_t priority);
uint32_t gic_acknowledge_irq(void);
void gic_end_of_irq(uint32_t irq);

#endif // GIC_H


